/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tintuna.sdigger.web.dao.impl;

import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import com.tintuna.sdigger.web.dao.StatementPaper;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 *
 * @author bsmith
 */
public class StatementMockImpl implements StatementPaper {

    List<String> order = new ArrayList();
    Map<String, String> header = new HashMap();

    public StatementMockImpl() {
        header.put("DATE", "Date");
        header.put("AMOUNT", "Amount");
        header.put("MERCHANT", "Merchent");
        header.put("BALANCE", "Balance");

        order.add("DATE");
        order.add("AMOUNT");
        order.add("MERCHANT");
        order.add("BALANCE");
    }

    @Override
    public Map<String, String> getHeader() {
        return header;
    }

    @Override
    public Iterator<Map<String, String>> getRowsIterator() {
        Iterator<Map<String, String>> rows = new RowsIterator();
        return rows;
    }

    @Override
    public List<String> getOrder() {
        return order;
    }

    private static class RowsIterator implements Iterator<Map<String, String>> {

        List<Map<String, String>> rows = new ArrayList();
        int index = 0;

        public RowsIterator() {
            for (int i = 0; i < 5; i++) {
                Map<String, String> row = new HashMap<String, String>();
                row.put("DATE", new StringBuilder("Date_").append(i).toString());
                row.put("AMOUNT", new StringBuilder("Amount_").append(i).toString());
                row.put("MERCHANT", new StringBuilder("Merchent_").append(i).toString());
                row.put("BALANCE", new StringBuilder("Balance_").append(i).toString());
                rows.add(row);
            }
        }

        @Override
        public boolean hasNext() {
            return rows.size() > index;
        }

        @Override
        public Map<String, String> next() {
            Map<String, String> row = null;
            if (this.hasNext()) {
                row = rows.get(index++);
            }
            if (row == null) {
                throw new RuntimeException("hasNext() is true but item is null.");
            }
            return row;
        }

        @Override
        public void remove() {
            if (rows.size() > 0) {
                rows.remove(--index);
            }
        }
    }
}
